﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Pages
{
    public partial class WithdrawList : PageBaseFrontend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (base.IsVerified)
                {
                    BindData();
                }
                else
                {
                    Response.Redirect(URL_INDEX);
                }
            }
        }

        #region##绑定
        /// <summary>
        /// 绑定
        /// 创建人：Wilson
        /// 创建时间：2012-01-17
        /// </summary>
        private void BindData()
        {
            IList<AUV5.Model.WithDrawLog> list = AUV5.BLL.WithDrawLogBLL.GetInstance().GetWithDrawListByUserId(VerifiedUserID);
            rptWithdraw.DataSource = list;
            rptWithdraw.DataBind();
        }
        #endregion

        #region##项点击
        /// <summary>
        /// 项点击
        /// 创建人：Wilson
        /// 创建时间：2012-01-17
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void rptWithdraw_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "without")
            {
                AUV5.Model.WithDrawLog log = AUV5.BLL.WithDrawLogBLL.GetInstance().GetDetail(Convert.ToString(e.CommandArgument));

                if (log != null)
                {
                    if (log.WithDrawStatus == Convert.ToInt32(AUV5.Common.Enum.auvWithDrawStatus.IsRequest))
                    {
                        log.LastStatus = log.WithDrawStatus;
                        log.WithDrawStatus = Convert.ToInt32(AUV5.Common.Enum.auvWithDrawStatus.Backout);

                        int i = AUV5.BLL.WithDrawLogBLL.GetInstance().Update(log);

                        if (i > 0)
                        {
                            Alert("撤销提现成功");
                            BindData();
                        }
                        else
                        {
                            Alert("撤销提现失败");
                        }
                    }
                }
            }
        }
        #endregion

        #region##绑定前激发
        /// <summary>
        /// 绑定前激发
        /// 创建人：Wilson
        /// 创建时间：2012-01-17
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptWithdraw_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Label lblId = e.Item.FindControl("lblId") as Label;               
                Label lblStatus = e.Item.FindControl("lblStatus") as Label;
                LinkButton lbtnWithout = e.Item.FindControl("lbtnWithout") as LinkButton;

                AUV5.Model.WithDrawLog log = AUV5.BLL.WithDrawLogBLL.GetInstance().GetDetail(lblId.Text.Trim());

                if (log != null)
                {                    
                    switch (Convert.ToInt32(lblStatus.Text.Trim()))
                    {
                        case (int)AUV5.Common.Enum.auvWithDrawStatus.Backout:
                            lblStatus.CssClass = "status status_bg4";
                            break;
                        case (int)AUV5.Common.Enum.auvWithDrawStatus.IsRequest:
                            lblStatus.CssClass = "status status_bg1";
                            break;
                        case (int)AUV5.Common.Enum.auvWithDrawStatus.Processing:
                            lblStatus.CssClass = "status status_bg2";
                            break;
                        case (int)AUV5.Common.Enum.auvWithDrawStatus.Completed:
                            lblStatus.CssClass = "status status_bg3";
                            break;
                        case (int)AUV5.Common.Enum.auvWithDrawStatus.Closed:
                            lblStatus.CssClass = "status status_bg5";
                            break;                       
                    }

                    lblStatus.Text = AUV5.Common.PageBase.GetEnumDesc(typeof(AUV5.Common.Enum.auvWithDrawStatus), log.WithDrawStatus);

                    if (log.WithDrawStatus == Convert.ToInt32(AUV5.Common.Enum.auvWithDrawStatus.IsRequest))
                    {
                        lbtnWithout.Visible = true;
                    }
                    else
                    {
                        lbtnWithout.Visible = false;
                    }                                       
                }
            }
        }
        #endregion
    }

}